package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    SearchService searchService;

    /**
     * 同步数据
     */
    @GetMapping("sync")
    public void sync() {
        searchService.sync();
    }

    /**
     * 创建索引
     */
    @GetMapping("index")
    public void createIndex() {
        searchService.createIndex();
    }


    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params){
        return searchService.list(params);
    }

    @PostMapping("/filters")
    private Map<String, List<String>> filters(@RequestBody RequestParams params){
        return searchService.filters(params);
    }
}
